package com.violet.utils;

import com.violet.config.RabbitmqConfig;
import com.violet.domain.po.BuyOrder;
import lombok.RequiredArgsConstructor;
import org.springframework.amqp.rabbit.core.RabbitTemplate;
import org.springframework.stereotype.Component;

@Component
@RequiredArgsConstructor
public class MQUtils {

    private final RabbitTemplate rabbit;

    /**
     * 发送支付成功消息
     * @param order 订单
     */
    public void sendPaid(BuyOrder order) {
        rabbit.convertAndSend(
            RabbitmqConfig.EXCHANGE_PAID,
            RabbitmqConfig.ROUTING_KEY_PAID,
            order.getId()
        );
    }

    /**
     * 发送确认收货消息
     */
    public void sendCompleted() {
        rabbit.convertAndSend(
            RabbitmqConfig.EXCHANGE_COMPLETED,
            RabbitmqConfig.ROUTING_KEY_COMPLETED,
            "确认收货成功"
        );
    }

}
